home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / bas_int1.zip / CMD_LINE.BAS < prev    next >
BASIC Source File  |  1991-06-26  |  2KB  |  61 lines

  1. '=================================================================
  2. 'Date: 04-11-91
  3. 'From: BRENT ASHLEY
  4. 'Subj: ORIGINAL COMMAND LINE; preserving lower case
  5. 'Conf: QBASIC (62)
  6.  
  7. 'The command line as entered at the DOS prompt, in all its mixed-case
  8. 'splendour, is found at offset &H81 of the program's PSP (Program Segment
  9. 'Prefix), with the length of the command string at offset &H80 of the
  10. 'PSP.
  11. '
  12. 'Finding your PSP from within QuickBASIC entails Interrupt calls.
  13. '                                                ~~~~~~~~~
  14. 'That same area of the PSP, however, is also the default disk transfer
  15. 'area for the program (or is it the default File Control Block? - I don't
  16. 'have my references handy) At any rate, I suspect QB always defines its
  17. 'own DTAs and FCBs, so the data won't be overwritten, but this cannot
  18. 'always be guaranteed.  It would be best, therefore, if you were to get
  19. 'this info, to get it as early in the program's execution as possible,
  20. 'especially before any file I/O.
  21. '======================================================================
  22.  
  23. DECLARE FUNCTION CmdLine$ ()
  24. DEFINT A-Z
  25. ' $INCLUDE: 'qb.bi'
  26.  
  27. PRINT "Here's the original command line:"
  28. PRINT "["; CmdLine; "]"
  29.  
  30. END
  31.  
  32. FUNCTION CmdLine$
  33.   '
  34.   ' CmdLine - returns original command line
  35.   '
  36.   DIM Regs AS RegType
  37.   STATIC CmdLen, CmdBuild$, i
  38.   '
  39.   ' DOS Interrupt 21h service 62h returns the segment
  40.   ' address of the running program's PSP in the bx register.
  41.   '
  42.   Regs.ax = &H6200
  43.   CALL Interrupt(&H21, Regs, Regs)
  44.   DEF SEG = Regs.BX
  45.   '
  46.   ' The command line's length is found at offset 80h of the PSP
  47.   ' and the actual command line starts at 81h
  48.   '
  49.   CmdBuild$ = ""
  50.   CmdLen = PEEK(&H80)
  51.   FOR i = 1 TO CmdLen
  52.     CmdBuild$ = CmdBuild$ + CHR$(PEEK(&H80 + i))
  53.   NEXT
  54.   '
  55.   ' restore BASIC data segment and return data
  56.   '
  57.   DEF SEG
  58.   CmdLine$ = CmdBuild$
  59. END FUNCTION
  60.  
  61.